<?php

/*
 * site/label_service.php
 *
 * Provide label management service
 *
 */

require_once( 'database_fct.php' );

Service::register( 'LabelService', 'Label Service', 'Label Management Service' );

class LabelService extends Service
{
	public function __construct()
	{
		parent::__construct();
		$this->registerMethod( 'add', array(T_STR), 'add a new label', 'helpless', false );
		$this->registerMethod( 'remove', array(T_INT), 'remove a label', 'helpless', false );
		$this->registerMethod( 'update', array(T_INT, T_STR), 'update a label', 'helpless', false );
		$this->registerMethod( 'getList', array(), 'list existing labels', 'helpless', true );
	}

	public function add( $name )
	{
		$id = SiteDBFct::addLabel($name);
		return $id;
	}

	public function remove( $id )
	{
		return SiteDBFct::removeLabel( $id );
	}

	public function update( $id, $name )
	{
		return SiteDBFct::updateLabel( $id, $name );
	}

	public function getList()
	{
		return array( 'labels'=>SiteDBFct::listLabels() );
	}
};

?>
